import {
  Component,
  ChangeDetectionStrategy,
  OnInit,
  OnDestroy,
  NgZone,
  ChangeDetectorRef,
  ElementRef,
  Input,
} from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd';

/**
 * 售后组件
 */
@Component({
  selector: 'app-product-repair',
  templateUrl: './product-repair.component.html',
  styleUrls: ['./product-repair.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ProductRepairComponent implements OnInit, OnDestroy {
  _codeName = null;
  @Input()
  set codeName(val) {
    if (val) {
      this._codeName = val;
      this.attachData(this._codeName);
    }
  }
  data = [];

  constructor(
    public http: _HttpClient,
    public msg: NzMessageService,
    private ngZone: NgZone,
    private cdr: ChangeDetectorRef,
  ) {}

  ngOnInit(): void {}

  ngOnDestroy(): void {}

  attachData(codeName) {
    this.ngZone.runOutsideAngular(() => {
      this.data = [];
      this.http.get(`/cf/report/prod/repairproblems/${codeName}`).subscribe((res: any) => {
        if (res.data) {
          this.data = res.data;
        }
      });
    });
  }
}
